package com.jsfcompref.solutech.backing;


import java.io.IOException;

import javax.faces.application.Application;
import javax.faces.component.html.HtmlInputSecret;
import javax.faces.component.html.HtmlInputText;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;





/**
 * Backing bean for login.jsp
 */


public class Login {

  private HtmlInputText userid;
  private HtmlInputSecret password;


  

  public Login() {

	 
  }


  public String login() {
	  
		// currentUser = new UserDTO();
		 
		// currentUser.setLogin(userid.getValue().toString());
		// currentUser.setPassword(password.getValue().toString());
	//	 userSvco.seConnecter(currentUser);
	  
      // pour naviguer vers la page de catalogue  
	  //return "success_client";
	  //pour naviguer vers la page de l'application admin
        return "success_admin";
  }



    public String logout() throws IOException{    
      ExternalContext ectx = FacesContext.getCurrentInstance().getExternalContext();
      HttpServletResponse response = (HttpServletResponse)ectx.getResponse();
      HttpSession session = (HttpSession)ectx.getSession(false);
      session.invalidate();    
      
      FacesContext ctx =  FacesContext.getCurrentInstance();
      Application app = ctx.getApplication();
      app.getNavigationHandler().handleNavigation(ctx, "/login.jsp", "login");
      
      // To avoid using the navigation handler you could also use...
      //response.sendRedirect("../index.jsp");*/
      return null;    
    
    }




  public void setUserid(HtmlInputText userid) {
    this.userid = userid;
  }


  public HtmlInputText getUserid() {
    return userid;
  }


  public void setPassword(HtmlInputSecret password) {
    this.password = password;
  }


  public HtmlInputSecret getPassword() {
    return password;
  }


}
